#!/usr/bin/python
# encoding: utf-8

from Minifier import Minifier
import re
 
class SgmlMinifier(Minifier):
	def minify(self, content = None):
		super(SgmlMinifier, self).minify(content)
		self.removeWhitespace().removeComments()
		return self
 
	def removeComments(self):
		self.content = self.content.replace('<!---->','')
		self.content = re.sub(r'\<!--[^[].*?-->', '', self.content)
		return self
 
	def removeWhitespace(self):
		self.content = re.sub(r'\s+', ' ', self.content)
		self.content = self.content.replace('< ', '<').replace('</ ', '</')
		self.content = self.content.replace(' >','>').replace(' />', '/>')
		return self

	#	'' ==
	#	''' == SYNTAX ERROR
	#	'\'' == '
	#	'\\ foo' == \ foo
	#	r'\\ foo' == \\ foo
	#	r' \'  ' ==  \'
	#	r'\'' == \'
	#	r'\' == SYNTAX ERROR